home *** CD-ROM | disk | FTP | other *** search
- /*
- * RENAME.C by Mitch Trachtenberg Cserv 73647,1447
- *
- * Megamax C code to create rename.prg, a skeleton program that allows
- * the renaming of a file "across directories"; that is, which
- * allows you to move a file into or out of a subdirectory without
- * having to copy it and then delete it. Frename(), below, is defined
- * in osbind.h (from either Atari or Megamax) as:
- * #define Frename(a,b,c) gemdos(0x56,a,b,c)
- * This program accepts its arguments from the command line; if they are
- * not found in the command line (or if the program is invoked from the
- * GEM desktop) it prompts for them.
- */
- #include "osbind.h"
- #include "stdio.h"
- #include "string.h"
- char current_pathname[100];
- char new_pathname[100];
- main(argc,argv)
- int argc;
- char **argv;
- {int retval;
- char *current;
- char *new;
- char *cur_name_only;
- if(argc<3) /* the command line didn't contain all necessary arguments */
- {current=current_pathname; /* so get them from the user */
- fputs("Current pathname: ",stdout); /* fputs doesn't append newline */
- gets(current_pathname); /* get first argument; current */
- new=new_pathname;
- fputs("New pathname: ",stdout); /* get second argument; new */
- gets(new_pathname);
- }
- else /* at least two command line arguments, assume they're legal */
- {current=argv[1]; /* first argument becomes current */
- new=argv[2]; /* second argument becomes new */
- }
-
- cur_name_only=rindex(current,'\\'); /* find last backslash in current */
- /* because, if it exists, it precedes the filename part of the string */
-
- if(*(new+strlen(new)-1)=='\\') /* if the new name given by user ends */
- /* with a backslash, append the old name */
- {if(cur_name_only)strcat(new,++cur_name_only);
- else strcat(new,current);
- }
-
- fputs("Now renaming \"",stdout);/* show user what you think you're doing */
- fputs(current,stdout);
- fputs("\" to \"",stdout);
- fputs(new,stdout);
- puts("\".");
- retval=Frename(0,current,new); /* then try to do it */
- /* and let user know how things went. */
- if(retval<0)
- {puts("Renaming failed. Check pathnames for validity.");
- exit(2);
- }
- else puts("Renamed.");
- exit(0);
- }
- əəəəəəəəəəəəəəəəəəəəəəəəəəəə